#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

WORKING_SUFFIX=$(if git status --porcelain | grep -qE '^(?:[^?][^ ]|[^ ][^?])\s'; then echo "-WIP"; else echo ""; fi)
BRANCH_PREFIX=$(git rev-parse --abbrev-ref HEAD)

if [[ $BRANCH_PREFIX =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]];
then
  echo $BRANCH_PREFIX
else
  echo "${BRANCH_PREFIX//\//-}-$(git rev-parse --short HEAD)$WORKING_SUFFIX"
fi
